<?php

namespace App\Models\Vocabulary;

use Illuminate\Database\Eloquent\Model;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Relations;
use App\Models\Category\Category;
use App\Models\Data\ClickLearn;

class Vocabulary extends Model
{
    use HasDateTimeFormatter;

    protected $table = 'vocabularys';
    protected $fillable = [
        'category_id', 'click_learn_id', 'type', 'item_id', 'sentence',
        'on_sort', 'game_type', 'sentence_id'
    ];

    const TYPE_AUDITION_WORD = 1;
    const TYPE_AUDITION_LOOK_SPELL_WORD = 2;
    const TYPE_SELECT_WORD_BLANKS = 3;
    const TYPE_READ_AFTER = 4;
    const TYPE_GAME = 5;
    const TYPE_IMAGE_LISTEN_PRACTICE = 6;
    const TYPE_CHINESE_SELECT_ENGLISH = 7;

    public static array $isShowMap = [
        self::TYPE_AUDITION_WORD => '练习听音选择',
        self::TYPE_AUDITION_LOOK_SPELL_WORD => '拼写',
        self::TYPE_SELECT_WORD_BLANKS => '练习选词填空',
        self::TYPE_READ_AFTER => '跟读',
        self::TYPE_GAME => '游戏',
        self::TYPE_IMAGE_LISTEN_PRACTICE => '听音看图练习',
        self::TYPE_CHINESE_SELECT_ENGLISH => '看中文选英文',
    ];

    public function category(): Relations\BelongsTo
    {
        return $this->belongsTo(Category::class);
    }

    public function click_learn(): Relations\BelongsTo
    {
        return $this->belongsTo(ClickLearn::class);
    }

    public function item(): Relations\BelongsTo
    {
        return $this->belongsTo(ClickLearn::class, 'item_id');
    }

    public function sentences(): Relations\BelongsTo
    {
        return $this->belongsTo(ClickLearn::class, 'sentence_id');
    }

    public function options(): Relations\HasMany
    {
        return $this->hasMany(VocabularyOption::class);
    }
}
